package main

import (
	"fmt"
	"golang_start/app/middleware"
	"golang_start/router"
	"net"

	"github.com/e421083458/golang_common/lib"
	"github.com/gin-gonic/gin"
	"google.golang.org/grpc"
)

func init() {

}

func main() {

	g := gin.Default()
	g.Use(middleware.Middleware)
	/*加载html模板*/
	g.LoadHTMLGlob("templates/*")
	router.ApiRouter(g)

	/*单开一个协成开启GRPC*/
	go Usegrpc()

	g.Run(lib.GetStringConf("base.http.port"))

}

/*开启grpc*/
func Usegrpc() {
	fmt.Println("开启Grpc")
	Address := lib.GetStringConf("base.grpc.port")
	listen, err := net.Listen("tcp", Address)
	if err != nil {
		fmt.Println("错误！", err.Error())
		// grpclog.Fatalf("Failed to listen: %v", err)
	}
	gs := grpc.NewServer()
	defer func() {
		gs.Stop()
		listen.Close()
	}()
	router.GrpcRouter(gs)

	err = gs.Serve(listen)
	// fmt.Println("到这里了2...")
	if err != nil {
		fmt.Println("Grpc端口开启失败", err.Error())
	}

}
